package cn.gxa.j229.bug.finance.controller.loanuser;

import cn.gxa.j229.bug.finance.BusinessException;
import cn.gxa.j229.bug.finance.pojo.LoanUser;
import cn.gxa.j229.bug.finance.pojo.UserMoney;
import cn.gxa.j229.bug.finance.service.loanuser.UserMoneyService;
import cn.gxa.j229.bug.finance.utils.JsonResult;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

/**
 * @Author: fenglin
 * @Date:2020/9/25 16:55
 * @Version 1.0
 */
@Controller
@RequestMapping("/userMoney")
public class UserMoneyController {

    @Resource
    UserMoneyService userMoneyService=null;


    JsonResult jsonResult=new JsonResult();

    @PostMapping("/selectAll")
    @ResponseBody
    public Map findAll(@RequestBody UserMoney userMoney) throws  BusinessException{
        Integer limit = userMoney.getLimit();
        Integer page = userMoney.getPage();
        List<Map<String, String>> selectAll = userMoneyService.selectAll(userMoney);
        int count = userMoneyService.selectAllCount(userMoney);
        jsonResult.put("count",count);
        jsonResult.setData(selectAll);
        jsonResult.setMsg("成功");
        jsonResult.setCode("200");
        return jsonResult.getValues();
    }


    @PostMapping("/selectPhoneAndName")
    @ResponseBody
    public Map selectPhoneAndName(@RequestBody UserMoney userMoney) throws BusinessException {

        Integer limit = userMoney.getLimit();
        Integer page = userMoney.getPage();
        String name = userMoney.getName();
        String phone = userMoney.getPhone();
        if (name!=null || !name.equals("") && phone!=null|| !phone.equals("")){
            List<Map<String, String>> selectPhoneAndName = userMoneyService.selectPhoneAndName(userMoney);
            int count = userMoneyService.selectPhoneAndNameCount(userMoney);
            jsonResult.put("count",count);
            jsonResult.setData(selectPhoneAndName);
            jsonResult.setMsg("成功");
            jsonResult.setCode("200");
        }else {
            List<Map<String, String>> selectAll = userMoneyService.selectAll(userMoney);
            int count = userMoneyService.selectAllCount(userMoney);
            jsonResult.put("count",count);
            jsonResult.setMsg("成功");
            jsonResult.setCode("200");
        }



        return jsonResult.getValues();
    }


    @PostMapping("/selectKey")
    @ResponseBody
    public Map selectLoanUserAndInvestmentUser(@RequestBody UserMoney userMoney) throws BusinessException{
        Integer limit = userMoney.getLimit();
        Integer page = userMoney.getPage();
        Integer userSock = userMoney.getUserSock();
        String name = userMoney.getName();
        String phone = userMoney.getPhone();




        if (userSock==null || userSock.equals("")){
            List<Map<String, String>> selectPhoneAndName = userMoneyService.selectPhoneAndName(userMoney);
            int count=userMoneyService.selectPhoneAndNameCount(userMoney);
            jsonResult.put("count",count);
            jsonResult.setData(selectPhoneAndName);
            jsonResult.setMsg("成功");
            jsonResult.setCode("200");

        }else  if (userSock == 0 && (name!= null || phone!= null)) {
                List<Map<String, String>> selectInvestmentuserPhoneAndName = userMoneyService.selectInvestmentuserPhoneAndName(userMoney);
            int count = userMoneyService.selectInvestmentuserPhoneAndNameCount(userMoney);
            jsonResult.put("count",count);
            jsonResult.setData(selectInvestmentuserPhoneAndName);


                jsonResult.setMsg("成功");
                jsonResult.setCode("200");
            }else if (userSock == 1 && (name!= null || phone!= null)) {
                List<Map<String, String>> selectLoanuserPhoneAndName = userMoneyService.selectLoanuserPhoneAndName(userMoney);
            int count = userMoneyService.selectLoanuserPhoneAndNameCount(userMoney);
            jsonResult.put("count",count);
            jsonResult.setData(selectLoanuserPhoneAndName);

                jsonResult.setMsg("成功");
                jsonResult.setCode("200");
            }else if (userSock==0) {
                List<Map<String, String>> selectInvestmentuser = userMoneyService.selectInvestmentuser(userMoney);
            int count = userMoneyService.selectInvestmentuserCount(userMoney);
            jsonResult.put("count",count);
            jsonResult.setData(selectInvestmentuser);

                jsonResult.setMsg("成功");
                jsonResult.setCode("200");
            }else if (userSock==1) {
                List<Map<String, String>> selectLoanuser = userMoneyService.selectLoanuser(userMoney);
            int count = userMoneyService.selectLoanuserCount(userMoney);
            jsonResult.put("count",count);
            jsonResult.setData(selectLoanuser);
                System.out.println("name4"+name);
                System.out.println("phone4"+phone);
                jsonResult.setMsg("成功");
                jsonResult.setCode("200");

            } else{

                jsonResult.setMsg("查找失败");
            }






        return jsonResult.getValues();
    }
}
